import json
from time import sleep

import requests
from IXueShu import RedisClient


class InsertToEs():
    r = RedisClient()

    def IntoEs(self):
        docname = self.r.get_doc_name()
        if docname:
            params = {'name': docname}
            headers = {'Content-Type': 'application/json'}
            jsonParams = json.dumps(params)
            r = requests.post('http://172.17.4.253:8080/v1/pdf/parse/name', headers=headers, data=jsonParams)
            self.r.push_download_doc(docname)
        else:
            sleep(3)


if __name__ == '__main__':
    bot = InsertToEs()
    bot.IntoEs()
    # while True:
    #     bot.IntoEs()
